<template>
  <div class="printForm">
    <div class="area-header">
      <span class="area-header-title">{{ $t('申请单') }}</span>
    </div>
    <table class="printTable">
      <tr>
        <td class="tit">{{ $t('申请标题') }}</td>
        <td colspan="3">{{ form.actTitle }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('申请人') }}</td>
        <td>
          {{ form.userName }}
        </td>
        <td class="tit">{{ $t('申请时间') }}</td>
        <td>{{ parseTime(form.applyTime) }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('申请部门') }}</td>
        <td>{{ form.applyDeptName }}</td>
        <td class="tit">{{ $t('使用部门') }}</td>
        <td>{{ form.useDeptName }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('合同编号') }}</td>
        <td>
          {{ form.conteractNum }}
        </td>
        <td class="tit">{{ $t('合同名称') }}</td>
        <td>
          {{ form.name }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('合同类型(一级)') }}</td>
        <td>
          {{ typeOnePayment(form.typeOne) }}
        </td>
        <td class="tit">{{ $t('合同类型(二级)') }}</td>
        <td>
          {{ typeTwoPayment(form.typeTwo) }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('预计签约时间') }}</td>
        <td>
          {{ parseTime(form.signingTime) }}
        </td>
        <td class="tit">{{ $t('对方签约主体名称') }}</td>
        <td>
          {{ form.company }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('收付款类型') }}</td>
        <td>
          {{ formatPayment(form.isPayment) }}
        </td>
        <td class="tit">{{ $t('是否用印') }}</td>
        <td>
          {{ formatSeal(form.isSeal) }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('有效期') }}</td>
        <td>
          {{ form.usefulLife }}
        </td>
        <td class="tit">
          <span v-if="form.typeOne === 'deal'">{{ $t('项目名称') }}</span>
          <span v-if="form.typeOne === 'fund'">{{ $t('基金名称') }}</span>
          <span v-if="form.typeOne === 'manager'">{{ $t('管理人') }}</span>
        </td>
        <td colspan="1">
          <MainBodySelect
            v-model="form.projectOrFund"
            :parameters="form.typeOne"
          />
        </td>
      </tr>
      <tr v-if="form.typeTwo === 'CG'">
        <td class="tit">{{ $t('采购申请') }}</td>
        <td>{{ form.purchasingApplication }}</td>
        <td class="tit">{{ $t('数量') }}</td>
        <td>{{ form.specifications }}</td>
      </tr>
      <tr v-if="form.isPayment === 'collection' || form.isPayment === 'payment'">
        <td class="tit">{{ $t('合同金额') }}{{ $t('金额单位') }}</td>
        <td colspan="3">
          {{ moneyFormat(form.money, 'w') }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('合同摘要') }}</td>
        <td colspan="3">
          {{ form.abstracts }}
        </td>
      </tr>
    </table>

    <!--用印明细-->
    <div v-if="form.isSeal === 'Y'" v-show="form.oaSealDetailList && form.oaSealDetailList.length > 0" style="margin-bottom: 20px;">
      <div class="area-header">
        <span class="area-header-title">{{ $t('用印明细') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('主体类型') }}</th>
          <th>{{ $t('用印主体') }}</th>
          <th>{{ $t('用印类型') }}</th>
          <th>{{ $t('备注') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.oaSealDetailList" :key="ind">
            <td>{{ typePayment(v.investMainType) }}</td>
            <td>
              <MainBodySelect
                v-model="v.investMain"
                :parameters="v.investMainType"
              />
            </td>
            <td>
              <el-select v-model="v.sealType" multiple>
                <el-option
                  v-for="dict in sealTypeDict"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </td>
            <td>{{ v.remark }}</td>
          </tr>
        </tbody>
      </table>

    </div>
    <!-- 签约 主体 -->
    <div v-if="form.oaContractPaymentList && form.oaContractPaymentList.length > 0" style="margin-bottom: 20px;">
      <div class="area-header">
        <span class="area-header-title">{{ $t('签约主体') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('主体类型') }}</th>
          <th>{{ $t('主体名称') }}</th>
          <th v-if="isShowStake">{{ $t('最新持股比例(%)') }}</th>
          <th>{{ $t('备注') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.oaContractPaymentList" :key="ind">
            <td>{{ typePayment(v.investType) }}</td>
            <td>
              <MainBodySelect
                v-model="v.investMain"
                :parameters="v.investType"
              />
            </td>
            <td v-if="isShowStake">{{ v.stake }}</td>
            <td>{{ v.remark }}</td>
          </tr>
        </tbody>
      </table>
    </div>

    <!-- 收付款计划 -->
    <div v-if="form.oaContractPlanList && form.oaContractPlanList.length > 0" v-show="nameReceiptPayment === '付款' && form.isPayment === 'payment'" style="margin-bottom: 20px;">
      <div class="area-header">
        <span class="area-header-title">{{ $t(nameReceiptPayment) }}{{ $t('计划') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('主体名称') }}</th>
          <th>{{ $t('预计付款时间') }}</th>
          <th>{{ $t('预计付款金额') }}{{ $t('金额单位') }}</th>
          <th>{{ $t('币种') }}</th>
          <th>{{ $t('备注') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.oaContractPlanList" :key="ind">
            <td>
              {{ v.investName }}
            </td>
            <td>{{ parseTime(v.paymentTime) }}</td>
            <td>
              {{ moneyFormat(v.paymentMoney, 'w') }}
            </td>
            <td>
              {{ formatCurrency(v.currency) }}
            </td>
            <td>{{ v.remark }}</td>
          </tr>
        </tbody>
      </table>
    </div>

    <div v-if="form.oaContractPlanList && form.oaContractPlanList.length > 0" v-show="nameReceiptPayment === '收款' && form.isPayment === 'collection'" style="margin-bottom: 20px;">
      <div class="area-header">
        <span class="area-header-title">{{ $t(nameReceiptPayment) }}{{ $t('计划') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('主体名称') }}</th>
          <th>{{ $t('预计收款时间') }}</th>
          <th>{{ $t('预计收款金额') }}{{ $t('金额单位') }}</th>
          <th>{{ $t('币种') }}</th>
          <th>{{ $t('款项名称') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.oaContractPlanList" :key="ind">
            <td>
              {{ v.investName }}
            </td>
            <td>{{ parseTime(v.collectionTime) }}</td>
            <td>
              {{ moneyFormat(v.collectionMoney, 'w') }}
            </td>
            <td>
              {{ formatCurrency(v.currency) }}
            </td>
            <td>{{ v.remark }}</td>
          </tr>
        </tbody>
      </table>
    </div>

    <!-- 合同关键条款 -->
    <div v-if="form.oaContractTermsList && form.oaContractTermsList.length > 0" style="margin-bottom: 20px;">
      <div class="area-header">
        <span class="area-header-title">{{ $t('合同关键条款') }}</span>
      </div>
      <table class="previewTable">
        <thead>
          <th>{{ $t('条款类型') }}</th>
          <th>{{ $t('条款内容') }}</th>
          <th>{{ $t('提醒时间') }}</th>
          <th>{{ $t('提醒人') }}</th>
        </thead>
        <tbody>
          <tr v-for="(v, ind) in form.oaContractTermsList" :key="ind">
            <td>
              {{ formatTerms(v.type) }}
            </td>
            <td>{{ v.remark }}</td>
            <td>{{ parseTime(v.remindTime) }}</td>
            <td>
              {{ v.nickName }}
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <!--文件-->
    <FileView :list.sync="form.fileList" data-type="oa_contract" :business-id="form.projectOrFund" :btn-show="!otherBtnHide" />

  </div>
</template>

<script>
  import { getOaContract } from '@/api/oa/contract/oaContract'
  import MainBodySelect from '@/components/MainBodySelect'
  export default {
    components: {
      MainBodySelect
    },
    data() {
      return {
        // 是否隐藏保存按钮
        btnHide: false,
        // 是否隐藏其它按钮
        otherBtnHide: false,
        loading: false,
        oaContractPaymentLoading: false,
        // 单选
        isSealOptions: [],
        isPaymentOptions: [],
        // 是否展示最新持股比例
        isShowStake: false,
        // 表单参数
        form: {},
        // 操作按钮默认不展示
        buttonShow: true,
        typeOneChangeValue: '',
        getTypeOneChange: [],
        title: '',
        sealTypeDict: undefined,
        // 收款  付款 名称
        nameReceiptPayment: '',
        oaContractPlanInvestMainOptions: [],
        oaContractPlanInvestMainOptionsTemp: [],
        contractInvestLoading: false,
        termsOption: [],
        currencyOption: [],
        typeOneOption: [],
        typeOption: []
      }
    },
    created() {
      this.$bus.$emit('async_done')
      this.getDicts('sys_yes_no').then(response => {
        this.isSealOptions = response.data
      })
      this.getDicts('collection_payment_no').then(response => {
        this.isPaymentOptions = response.data
      })
      this.getDicts('seal_type').then(response => {
        this.sealTypeDict = response.data
      })
      this.getDicts('currency').then(response => {
        this.currencyOption = response.data
      })
      this.getDicts('key_terms_tyoe').then(response => {
        this.termsOption = response.data
      })
      this.getDicts('contract_type').then(response => {
        this.typeOneOption = response.data
      })
      this.getDicts('main_body_type').then(response => {
        this.typeOption = response.data
      })
    },
    methods: {
      formatTerms(val) {
        return this.selectDictLabel(this.termsOption, val)
      },
      formatCurrency(val) {
        return this.selectDictLabel(this.currencyOption, val)
      },
      formatSeal(val) {
        return this.selectDictLabel(this.isSealOptions, val)
      },
      formatPayment(val) {
        return this.selectDictLabel(this.isPaymentOptions, val)
      },
      typeOnePayment(val) {
        return this.selectDictLabel(this.typeOneOption, val)
      },
      typeTwoPayment(val) {
        return this.selectDictLabel(this.getTypeOneChange, val)
      },
      typePayment(val) {
        return this.selectDictLabel(this.typeOption, val)
      },
      // 初始化数据
      init(data) {
        if (data != null && data !== '') {
          getOaContract(data.id).then(response => {
            this.form = response.data
            this.typeOneChange(this.form.typeOne)
            this.form.isPayment = response.data.isPayment
            this.isPaymentChange(this.form.isPayment)
            this.form.isSeal = response.data.isSeal
          })
        } else {
          this.reset()
        }
      },
      typeOneChange(typeOne) {
        // 显示 状态
        this.typeOneChangeValue = typeOne
        // 获取字典
        var temp = ''
        if (typeOne === 'fund') {
          temp = 'fund_contract_type'
        } else if (typeOne === 'manager') {
          temp = 'manager_coontract_type'
        } else {
          temp = 'deal_contract_type'
        }
        this.getDicts(temp).then(response => {
          this.getTypeOneChange = response.data
        })
      },
      isPaymentChange(val) {
        if (val === 'collection') {
          this.nameReceiptPayment = '收款'
        } else if (val === 'payment') {
          this.nameReceiptPayment = '付款'
        } else {
          this.nameReceiptPayment = '收付款'
        }
        if (this.form.typeTwo === 'TZXY' && val === 'payment') {
          this.isShowStake = true
        } else {
          this.isShowStake = false
        }
      },
      // 表单重置
      reset() {
        this.form = {
        id: undefined,
        applyUserId: this.$store.state.user.userId,
        applyTime: new Date(),
        signingTime: undefined,
        name: undefined,
        money: undefined,
        typeOne: undefined,
        typeTwo: undefined,
        company: undefined,
        projectOrFund: undefined,
        isPayment: 'no',
        isSeal: 'N',
        useSealOne: undefined,
        useSealTwo: undefined,
        abstracts: undefined,
        actTitle: undefined,
        createBy: undefined,
        updateBy: undefined,
        createTime: undefined,
        updateTime: undefined,
        delFlag: undefined
        }
        this.resetForm('form')
      }
    }
  }
</script>
